﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EnvDTE;
using EnvDTE80;
using EnvDTE90;
using EnvDTE100;
using Microsoft.VisualStudio.VCProjectEngine;

namespace GnProjectAssist
{
    static public class GnVCProject
    {
        static public VCProject GetSelectProject( DTE appl )
        {
            try
            {
                SelectedItems selectItems = appl.SelectedItems;
                SelectedItem selectItem = selectItems.Item( 1 );
                VCProject vcProject = GetSelectProject( selectItem );
                return vcProject;
            }
            catch
            {
            }
            return null;
        }

        static public VCProject GetSelectProject( SelectedItem selectItem )
        {
            VCProject vcProject = null;
            if( selectItem.Project != null )
            {
                vcProject = selectItem.Project.Object as VCProject;
                return vcProject;
            }
            else
            {
                if( selectItem.ProjectItem != null &&
                    selectItem.ProjectItem.ContainingProject != null )
                {
                    vcProject = selectItem.ProjectItem.ContainingProject.Object as VCProject;
                    return vcProject;
                }
            }
            return null;
        }
    }
}
